package com.framework.spring.context.bean;

import com.framework.spring.context.event.ABeanInitEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@Slf4j(topic = "e")
public class A implements InitializingBean {

	@Autowired
	private C c;

	@Autowired
	ApplicationContext applicationContext;

	public A() {
		log.info("A construct");
	}

	/**
	 * spring bean生命周期初始化回调
	 * @throws Exception
	 */
	@Override
	public void afterPropertiesSet() throws Exception {
		log.info("A#afterPropertiesSet");
		applicationContext.publishEvent(new ABeanInitEvent(applicationContext));
	}

	public C getC() {
		return c;
	}

	public void setC(C c) {
		log.info("A#setC");
		this.c = c;
	}

	@PostConstruct
	public void init() {
		log.info("A#@PostConstruct#init");
	}
}
